<template>
    <div class="tip-wrap">
        <div class="tip">{{ tip }}</div>
        <div class="tip-btn" v-if="!isApp" @click="openApp">打开APP</div>
        <slot></slot>
        <!-- <share-page ref="sharePageRef"></share-page> -->
    </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import { useStore } from 'vuex';
import SharePage from '@/components/share.vue';
import {useRoute} from 'vue-router';

const route = useRoute();
const store = useStore();
const sharePageRef = ref(null);

const props = defineProps({
    openAppBtn: {
        type: Boolean,
        default: false
    },
    tip: {
        type: String,
        default: '浏览器不支持扫码，请前往APP签到',
    }
});

defineExpose({
    sharePageRef
})

const emit = defineEmits([
    'open-app'
])

const isApp = computed(() => {
    console.log('isApp----', store.state.curUserAgent?.isApp)
    return store.state.curUserAgent?.isApp; 
});
const isWechat = computed(() => {
    console.log('weinxin----', store.state.curUserAgent?.isWechat)
    return store.state.curUserAgent?.isWechat;
});

const openApp = () => {
    console.log('weinxin----', isWechat.value)
    if(!isApp.value) {
        // if(isWechat.value) {
        //     sharePageRef.value.openShare();
        // } else {
            let url = window.location.href;
            if(route.name === 'shareDetail') {
                url.replace('/share', '/detail');
            }
            let appUrl = `/appidx/download?func=miniProgram&url=${encodeURIComponent(url)}`
            G_go(appUrl);
        // }    
    }
}
</script>

<style lang="scss" scoped>
.tip-wrap {
    width: 100%;
    height: 54px;
    background: #fff;
    font-size: 14px;
    color: #0084F6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    box-shadow: 0px 4px 6px #8c95b314;
}
.tip {
    width: 255px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tip-btn {
    padding: 7px 12px;
    background: #0084F6;
    border-radius: 17px;
    font-size: 13px;
    color: #FFFFFF;
    line-height: 20px;
    text-align: center;
    white-space: nowrap;
}
</style>